﻿using System.Linq;
namespace SanguoSharp.Server.Cards
{
    public sealed class 五谷丰登 : AllPlayersCard
    {
        private sealed class HarvestResponseHandler : ResponseHandler
        {
            private 五谷丰登 card;

            public HarvestResponseHandler(五谷丰登 card, Player requested)
                : base(RequestType.五谷丰登, requested)
            {
                this.card = card;
            }

            protected override void OnRespondCard(Card card)
            {
                if (!Game.GameTable.Selection.Contains(card))
                    throw new BadCardException();

                Game.GameTable.PlayerPickFromSelection(RequestedPlayer, card);
                End();
            }
        }
        public 五谷丰登(Game game, int id, CardSuit suit, CardRank rank)
            : base(game, id, CardType.五谷丰登, suit, rank, true)
        {
        }

        protected override void OnPlay()
        {
            base.OnPlay();
            Game.GameTable.DrawIntoSelection(Game.Players.Count(p => p.IsAlive && p.HasCardEffect(this)), null);
        }

        protected override ResponseHandler OnPlay(Player owner, Player targetPlayer)
        {
            return new HarvestResponseHandler(this, targetPlayer);
        }
    }
}

